1 00:00:00,530 --> 00:00:00,830 All right. 2 00:00:00,830 --> 00:00:04,400 So now that we have our teleporter put together, let's do some scripting. 3 00:00:04,400 --> 00:00:11,390 Let's make it so that when somebody steps on that green pad, they're pad A, they are teleported up 4 00:00:11,390 --> 00:00:19,370 into this box, and the floor of that box is pad B, So we need to remember that pad A to pad B, Let's 5 00:00:19,370 --> 00:00:24,440 go to the teleporter up here on the top level of the model and then add a script. 6 00:00:25,490 --> 00:00:26,300 Here we go. 7 00:00:26,300 --> 00:00:28,670 And let's call the script teleport 8 00:00:31,160 --> 00:00:33,170 and we'll get rid of the print statement. 9 00:00:33,200 --> 00:00:34,940 We need a couple of variables. 10 00:00:34,940 --> 00:00:39,230 We'll do pad A, of course, and that's where the touch events are going to happen. 11 00:00:39,230 --> 00:00:43,340 So we'll say, Script dot Parent, That's the teleporter. 12 00:00:43,340 --> 00:00:49,970 We need to go down to the teleporter, a model and in the model we are going to get pad A run, do the 13 00:00:49,970 --> 00:00:52,350 same for pad B, right? 14 00:00:52,520 --> 00:00:54,290 So this is our destination. 15 00:00:54,290 --> 00:00:55,730 We're not going to have a touched event on it. 16 00:00:55,730 --> 00:00:57,020 We're going to go there. 17 00:00:57,020 --> 00:00:58,280 So I still need it. 18 00:00:58,280 --> 00:01:06,560 Script dot parent Teleporter B dot pad B Now we need a function local function. 19 00:01:06,560 --> 00:01:12,740 We'll call this trans locate and other parts going to get passed in. 20 00:01:13,160 --> 00:01:14,240 Why is that? 21 00:01:14,240 --> 00:01:21,920 Well, our pad, a touched event is going to be connected to trans locate. 22 00:01:22,790 --> 00:01:23,480 There we go. 23 00:01:23,480 --> 00:01:25,370 Get rid of those two extra parentheses. 24 00:01:25,370 --> 00:01:30,980 So when we touch pad A, this is going to be called and it's going and this is going to be like a foot 25 00:01:30,980 --> 00:01:31,760 or something, right? 26 00:01:31,760 --> 00:01:33,260 Because this is a typical touch event. 27 00:01:33,260 --> 00:01:37,820 So the part that touched your pad A is going to get passed in to translocate. 28 00:01:38,030 --> 00:01:39,560 We're going to hope it's a foot. 29 00:01:39,560 --> 00:01:41,720 So we're going to look for the humanoid root part. 30 00:01:41,750 --> 00:01:45,230 Humanoid root part is part of a character. 31 00:01:45,230 --> 00:01:49,700 It's the part that holds the position and orientation of the character. 32 00:01:49,700 --> 00:01:56,600 So if the other parts of the foot, the parent will be the character, then we'll do a fine first child 33 00:01:58,280 --> 00:01:59,780 of humanoid root part. 34 00:02:02,720 --> 00:02:07,880 And if it is a character of some type, we will have the humanoid part. 35 00:02:07,880 --> 00:02:11,870 So we're going to do an EF just in case there isn't a tree or a ball or something like that that hit 36 00:02:11,870 --> 00:02:12,500 the pad. 37 00:02:13,100 --> 00:02:16,860 Now a zombie could theoretically touch that pad, eh? 38 00:02:16,940 --> 00:02:22,160 So we want to only teleport character or players, not characters, not just characters, but playing 39 00:02:22,160 --> 00:02:23,260 characters, right? 40 00:02:23,270 --> 00:02:24,410 So we need a player. 41 00:02:24,410 --> 00:02:25,490 How do we get a player? 42 00:02:25,490 --> 00:02:27,560 We get a player from the player service. 43 00:02:27,560 --> 00:02:31,970 If we look down here, players, that's the player service. 44 00:02:31,970 --> 00:02:33,770 How do we get a reference to that? 45 00:02:33,770 --> 00:02:35,390 Well, we can do local. 46 00:02:35,750 --> 00:02:37,520 I'm going to call it players. 47 00:02:37,520 --> 00:02:38,960 Hopefully that's not too close. 48 00:02:38,960 --> 00:02:39,920 It'll mess you up. 49 00:02:41,120 --> 00:02:45,110 We'll say game, get service players. 50 00:02:45,110 --> 00:02:49,280 That is a variable to that and that keeps track of our players. 51 00:02:49,280 --> 00:02:58,340 So if I do player's colon, get player from character while I have a character, if I have a humanoid 52 00:02:58,340 --> 00:03:00,740 root part, it just might not be a player. 53 00:03:00,740 --> 00:03:08,060 But let's check, we'll do other part parent that would be that would be the character if the player 54 00:03:08,090 --> 00:03:09,410 got returned. 55 00:03:09,410 --> 00:03:10,820 We know it's a player. 56 00:03:10,820 --> 00:03:16,520 If it did get returned, we can get the humanoid root part C frame, which holds the numbers for the 57 00:03:16,520 --> 00:03:19,070 position in the orientation of the character. 58 00:03:19,100 --> 00:03:27,350 We're going to create a new C frame using Pad B's position, right? 59 00:03:27,350 --> 00:03:29,390 But we're not going to worry about orientation. 60 00:03:29,390 --> 00:03:31,850 We're going to let it have the default orientation. 61 00:03:31,850 --> 00:03:37,880 So the character is going to go into our box and they're going to be facing down the Z axis. 62 00:03:37,880 --> 00:03:43,250 That is the default position that you would be in if you did not give an orientation to your C frame. 63 00:03:43,250 --> 00:03:45,710 But we will do that later, not today. 64 00:03:45,710 --> 00:03:52,370 But what we also want to do is make sure we move our C frame our character up a little bit so we don't 65 00:03:52,370 --> 00:03:55,010 get put right in the middle of the floor. 66 00:03:55,010 --> 00:04:02,450 And we can do that by using a vector three at to do vector three new zero on the x three studs, hi 67 00:04:02,480 --> 00:04:03,770 zero on the Y. 68 00:04:03,770 --> 00:04:08,840 So essentially we're moving our C frame up three studs. 69 00:04:08,840 --> 00:04:11,570 So that's where our character is going to end up in the box. 70 00:04:11,570 --> 00:04:12,440 Pretty cool. 71 00:04:12,440 --> 00:04:13,670 Let's go ahead and try it. 72 00:04:17,950 --> 00:04:19,270 And where's our teleporter? 73 00:04:19,300 --> 00:04:20,020 There it is. 74 00:04:20,710 --> 00:04:20,950 Boom! 75 00:04:21,010 --> 00:04:21,930 We're in a box. 76 00:04:21,940 --> 00:04:23,110 Let's check for errors. 77 00:04:23,140 --> 00:04:23,920 Output. 78 00:04:24,660 --> 00:04:25,830 No errors. 79 00:04:26,130 --> 00:04:27,150 All right. 80 00:04:27,240 --> 00:04:29,910 I will continue this in the next video.